import ReactDOM from "react-dom/client";
import { mduiComponents, setColorScheme } from "./mdui";
import App from "./App";
import "./index.css";

async function loadPage() {
  try {
    await Promise.all(
      mduiComponents.map((element) => customElements.whenDefined(element)),
    );
    setColorScheme("#6f8de1");
    const root = document.querySelector("#root");
    if (root) {
      ReactDOM.createRoot(root).render(<App />);
    } else {
      alert("未找到容器");
    }
  } catch (error: unknown) {
    alert("MDUI 组件加载失败: " + (error as string));
  }
}

void loadPage();
